<?php
/**
 * $Id$
 *
 * PHP versions 5
 *
 * Copyright (c) 2012, PANEL_CONROLLER
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the University of California, Berkeley nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author     Ivan Martins
 * @author     Ivan Martins
 * @copyright  
 * @license    BSD
 * @version    $Id$
 * @link       
 * @since      2012
 */
 if (strpos($_SERVER["SCRIPT_NAME"],"database2.class.php")!=FALSE) {
  header("Location: ../index.php");
  exit;
}
class Util {

function sendMail($newsletter,$mail){


$newsletterMail = "http://www.qualisample.com/controller/newslatterpage.php?newsletter=".$newsletter;
//ob_start();
$includeFile = file_get_contents($newsletterMail);
//$conteudo = ob_get_contents();
//ob_end_clean();

$para = "$mail";
$assunto = "Teste de Página";
$headers = 'From: QualiSample <respondent@qualisample.com>' . "\r\n" .
    'Reply-To: ivanmartins@mfries.com' . "\r\n" .
    'Content-type: text/html'."\r\n".
    'X-Mailer: PHP/' . phpversion();


$mailsend = mail($para,$assunto,$includeFile ,$headers);
if($mailsend){
	return "Ok";
}else{
	return "Not Ok";
}	
}//end function

function menu($area){


if($area=='newsletter'){
	echo'
	<a href="newsletterList.php">Newsletters</a>
	<a href="newsletterContList.php">Content</a>
	<a href="newsletterFooList.php">Footer</a>
	<a href="directMailList.php">Send</a>
	';
}

}//end function


function array2table($array, $recursive, $null, $show, $options)
{
    // Sanity check
    if (empty($array) || !is_array($array)) {
        return false;
    }
 
    if (!isset($array[0]) || !is_array($array[0])) {
        $array = array($array);
    }
 
    // Start the table
    $table = "<table>\n";
 
    // The header
    $table .= "\t<tr>";
    // Take the keys from the first row as the headings
	$table .= "<th></th>";
    foreach (array_keys($array[0]) as $heading) {
        $table .= '<th>' . $heading . '</th>';
    }
    $table .= "</tr>\n";
 
    // The body
    foreach ($array as $row) {
	          if (($i % 2) == 1){ 
		   	$fundo="#FEFEFE"; 
		  }else{ 
		  	$fundo="#CDCDCD"; 
		  }
		  $i++;
		 $table .= "<tr bgcolor=$fundo>\n";
       		$table .= "<td><input type='checkbox' name='uid_".$row['ID']."' id='uid_".$row['ID']."' value ='".$row['ID']."' /></td>";
        foreach ($row as $cell) {
            $table .= '<td>';
 			
            // Cast objects
            if (is_object($cell)) { $cell = (array) $cell; } 
 
            if ($recursive === true && is_array($cell) && !empty($cell)) {
                // Recursive mode
                $table .= "\n" . array2table($cell, true, true) . "\n";
            } else {
                $table .= (strlen($cell) > 0) ?
                    htmlspecialchars((string) $cell) :
                    $null;
            }
 
            $table .= '</td>';
			
			
        }
		   if($show==TRUE){
		
		$table .= "<td><a href='".$options['view']."".$row['UID']."' target='_blank'><img src='images/preview_icon.png' width='20' height='20' alt='Preview' border='0'/></a></td>\n";
			 $table .= "<td><a href='".$options['update']."".$row['ID']."' ><img src='images/update_icon.png' width='20' height='20' alt='Update' border='0' /></a></td>\n";
			 $table .= "<td><a href='".$options['remove']."".$row['ID']."' ><img src='images/remove_icon.png' width='20' height='20' alt='Remove' border='0' /></a></td>\n";
 
        $table .= "</tr>\n";
		}
    }
 
    $table .= '</table>';
    return $table;
}

	
}//end class

?>